from datetime import datetime

from rest_framework.authentication import BasicAuthentication
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView

import logging

from rest_framework.viewsets import ViewSet

from app_service.serializers.serializer import PostSerializer, ListSerializer

logger = logging.getLogger(__name__)


class ClassAPIView(APIView):
    authentication_classes = []
    permission_classes = []

    def get_permissions(self):
        return self.permission_classes

    def get(self, request, ):
        logger.info('get')
        response = Response()
        return response

    def post(self, request):
        ser = PostSerializer(data=self.request.data)
        ser.is_valid(raise_exception=True)
        date_time = ser.validated_data.get('date_time')
        logger.info(f'date_time:{date_time}.')
        response = Response()
        return response


class ClassViewSet(ViewSet):
    authentication_classes = []
    permission_classes = []

    @action(methods=['post'], detail=False)
    def list_ser(self, request):
        ser = ListSerializer(data=self.request.data)
        ser.is_valid(raise_exception=True)
        list_field = ser.validated_data.get('list_field')
        logger.info(f'list_field:{list_field}.')
        response = Response()
        return response
